import { Get, Post } from '@/utils/request.ts'
import { reqAddHuatiBody, respUploadData, reqArticalData } from '@/pages/forum/api/types/huati'
import {articleForm} from "@/pages/forum/types/loadBoard";
import {Obj} from "@/types/common";
enum API {
  ADD_HUATI_URL = '/bbs/api/topic/add',
  ADD_TOPIC_URL = '/bbs/api/forum/postArticle',
  HUATI_LIST_URL = '/bbs/api/topic/list/strKey',
  UPLOAD_IMAGE_URL = '/bioinfor/auth/upload/uploadImage',
  UPLOAD_FILE_URL = '/bioinfor/auth/upload/uploadFile',
  GET_LOAD_BOARD = '/bbs/api/board/loadBoard',
  GET_BOARD_TEMPLATE = '/bbs/api/model/list',
  GET_TOTAL_ARITICAL_LIST = '/bbs/api/forum/loadArticle',
  GET_KEYWORDS_DATA = '/bbs/api/forum/search'
}

// 添加话题
export const reqCreateHuati = (reqData: reqAddHuatiBody) =>
  Post<boolean>(API.ADD_HUATI_URL, reqData)
//发帖
export const saveTopic = (reqData: articleForm) =>
    Post<boolean>(API.ADD_TOPIC_URL, reqData)
//获取文章接口
export const getToltalArticle = (reqData: reqArticalData) =>
    Post<boolean>(API.GET_TOTAL_ARITICAL_LIST, reqData)
//搜索
export const searchData = (reqData: string) =>
    Get<boolean>(API.GET_KEYWORDS_DATA, {keyword: reqData})
//获取发帖所有分类
export const getTotalLoadBoard = () =>
    Post<boolean>(API.GET_LOAD_BOARD)
//获取发帖模版
export const getBoardTemplate = () =>
    Get<boolean>(API.GET_BOARD_TEMPLATE, {pageNum: 1, pageSize: 999})
// 获取话题内容
export const reqGetHuatiList = (strKey?: string) =>
  Get<string[]>(API.HUATI_LIST_URL, { strKey })

export const reqUploadImage = (reqData: any, onUploadProgress?: Function, controller?: Object) =>
  Post<respUploadData>(
    API.UPLOAD_IMAGE_URL,
    reqData,
    {},
    { 'Content-Type': 'multipart/form-data' },
     onUploadProgress,
      controller
  )
export const reqUploadFile = (reqData: any, onUploadProgress?: Function, controller?: Object) =>
    Post<respUploadData>(
        API.UPLOAD_FILE_URL,
        reqData,
        {},
        { 'Content-Type': 'multipart/form-data' },
        onUploadProgress,
        controller
    )
